<template>
  <view class="comp-b">
    <text class="comp-title">子组件B</text>
    <view class="value-group">
      <text>CompA组件传进来的值:</text>
      <text class="blue-text">{{ result }}</text>
    </view>
    <view class="input-group">
      <text class="label">回传值:</text>
      <input type="text" v-model="callbackValue" class="input gray-input" />
      <button @click="sendOutside()" class="small-btn">回传</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      result: '',
      callbackValue: ''
    };
  },
  created() {
    uni.$on('getIntent', (msg) => {
		console.error("----CompB----getIntent----->"+msg);
      this.result = msg;
    });
  },
  destroyed() {
    uni.$off('getIntent');
  },
  methods: {
    sendOutside() {
	 console.warn("----CompB----senOutside------>"+this.callbackValue);
      this.$emit('callBackFun', this.callbackValue);
    }
  }
};
</script>

<style scoped>
.comp-b {
  background-color: lightgreen;
  padding: 30rpx;
  border-radius: 10rpx;
}
.comp-title {
  display: block;
  font-size: 36rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
}
.value-group {
  margin-bottom: 20rpx;
  font-size: 28rpx;
}
.blue-text {
  color: blue;
  font-weight: bold;
  background-color: #fff;
  padding: 2rpx 10rpx;
  margin-left: 10rpx;
}
.input-group {
  display: flex;
  align-items: center;
}
.label {
  width: 80rpx;
  font-size: 28rpx;
}
.input {
  flex: 1;
  height: 60rpx;
  border: none;
  padding: 0 20rpx;
  font-size: 28rpx;
}
.gray-input {
  background-color: #ccc;
  color: #000;
}
.small-btn {
  width: 120rpx;
  height: 60rpx;
  line-height: 60rpx;
  font-size: 24rpx;
  margin-left: 20rpx;
}
</style>